package com.crm.action;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.crm.easyui.Grid;
import com.crm.po.Fp1;
import com.crm.service.Fp1Service;
import com.crm.util.ResponseUtils;

public class Fp1Action extends Servlet {

	private static final long serialVersionUID = 1116994082953057033L;
	
	@SuppressWarnings("unchecked")
	public void getFp1List(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Fp1Service service = new Fp1Service();
		Map<String, Object> map = service.getFp1s(request);
		
		Grid grid = new Grid();
		grid.setTotal((Integer)map.get("count"));
		grid.setRows((List<Fp1>)map.get("rows"));
		
		ResponseUtils.printJson(response, null, grid, null,null);
	}
	
	public void saveOrUpdateFp1(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Fp1Service service = new Fp1Service();

		boolean result = service.saveOrUpdateFp1(request);
		
		String value = result ? "ok": "新增或修改数据失败，请检查您的输入数据是否有效。";
		ResponseUtils.printString(response, value);
	}
	
	public void deleteFp1(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Fp1Service service = new Fp1Service();

		boolean result = service.deleteFp1s(request);
		
		String value = result ? "ok": "删除数据失败，请检查您的系统是否出现错误。";
		ResponseUtils.printString(response, value);
	}
	
	public void recoverFp1(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Fp1Service service = new Fp1Service();

		boolean result = service.recoverFp1s(request);
		
		String value = result ? "ok": "恢复数据失败，请检查您的系统是否出现错误。";
		ResponseUtils.printString(response, value);
	}
	
	public void reallyDeleteFp1(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Fp1Service service = new Fp1Service();

		boolean result = service.reallyDeleteFp1s(request);
		
		String value = result ? "ok": "彻底删除数据失败，请检查您的系统是否出现错误。";
		ResponseUtils.printString(response, value);
	}
	
	public void mathJJCC(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Fp1Service service = new Fp1Service();

		double result = service.mathJJCC(request);
		
		String temp = result + "";
		String returnValue = temp;
		String[] args = temp.split("\\.");
		if(temp.indexOf(".") < 0){
			returnValue = returnValue + ".00";
		}else if(args[1] == null || args[1].length() == 0){
			returnValue = returnValue + "00";
		}else if(args[1].length() == 1){
			returnValue = returnValue + "0";
		}
		
		ResponseUtils.printString(response, returnValue);
	}
	
	public void mathBatchAdd(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Fp1Service service = new Fp1Service();

		String result = service.mathBatchAdd(request);

		ResponseUtils.printJson(response, result);
	}
	
	public void exportFp1Excel(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Fp1Service service = new Fp1Service();
		service.exportFp1s(request, response);
	}

}
